package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.FileUploadService;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Tag(name="文件上传")
@RestController
@RequestMapping("/admin/system")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService ;

    @Operation(summary = "图片上传")
    @PostMapping(value = "/fileUpload")   //文件上传必须post请求。
    public Result<String> fileUploadService(@RequestParam(value = "file") MultipartFile multipartFile) { //前端使用element-plus提供上传组件，参数名称默认:file
        String fileUrl = fileUploadService.fileUpload(multipartFile) ; //minio服务器上资源完整路径。通过这个路径可以预览图片。访问策略： public
        return Result.build(fileUrl , ResultCodeEnum.SUCCESS) ;
    }

}
